package game.classes;

import game.Game;
import game.sound.CollideSound;
import game.sound.ShipBlastSound;
import java.awt.Graphics;
import java.util.Vector;

/**
 * @author Chris
 */
public class Ship extends GameObject {

    public static final int WIDTH = 32;
    public static final int HEIGHT = 32;
    public static final int MAXENERGY = 5;
    private int SPEED = 4;
    private int BLAST_INTERVAL = 200;
    private int dx;
    private long last_blast;
    private int energy;

    public Ship(int x, int y) {
        super("player.gif", x, y);
        last_blast = 0;
        dx = 0;
        energy = MAXENERGY;
    }

    public void move(int delta) {
        dx = delta * SPEED;
    }

    public void fire(Vector shots, boolean local) {
        java.util.Date d = new java.util.Date();
        if (d.getTime() - last_blast > BLAST_INTERVAL) {
            last_blast = d.getTime();
            shots.add(new Shot(getX() + WIDTH / 2 - Shot.WIDTH / 2, getY(), GOUP, local));
            new ShipBlastSound();
        }

    }

    @Override
    public void draw(Graphics g) {
        if (getX() + dx > 0 && getX() + dx + WIDTH < Game.BWIDTH) {
            setX(getX() + dx);
        } else {
            dx = 0;
        }
        super.draw(g);
    }

    public int getEnergy() {
        return energy;
    }

    public void setEnergy(int energy) {
        this.energy = energy;
    }

    public void collided() {
        new CollideSound();
    }
}
